import { RootState } from '@/types/store'
import { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'

// 组件需要发请求将数据存入state + 从store拿数据使用
export default function useInitState(activeCreate: () => void) {
  const dispatch = useDispatch()
  useEffect(() => {
    dispatch(activeCreate())
  }, [dispatch, activeCreate])

  const state = useSelector((state: RootState) => {
    return state
  })

  return state
}
